/*
 * BOSSコントロール
 */
void
bosscontrol(int i)
	{
	int	xs,ys,zs;
	int	j;
	int	dat[8]={
		  0, 8,  0,-8,  0,-8,  0, 8};	// BOSS2用移動データ

	// カウント
	enemy[i].deg++;
	if ( enemy[i].deg > 159 ) enemy[i].deg = 0;

	// 断末魔
	if ( enemy[i].hp < 100 )
		{
		if ( animecount%4 == 0 )
			{
			xs = random(30) - random(30);
			ys = random(30) - random(30);
			zs = random(30) - random(30);
			bakuinit(enemy[i].x,enemy[i].y,enemy[i].z,xs,ys,zs);
			}
		enemy[i].z += 2;
		enemy[i].hp--;
		if ( enemy[i].hp <= 0 )
			{
			for ( j = 0 ; j < MAXBAKU ; j++ )
				{
				baku[j].flag = 0;
				}
			PcmPlay(1,ADP_BBAKU);
			enemy[i].flag = 2;
			oe[i].geometryTop = model3;
			oe[i].geometryLength = sizeof(model3) / sizeof(int);
			oe[i].material = NULL;
			ship.score += enemy[i].score;
			for ( j = 0 ; j < MAXBAKU ; j++ )
				{
				xs = random(60) - random(60);
				ys = random(60) - random(60);
				zs = random(60) - random(60);
				bakuinit(enemy[i].x,enemy[i].y,enemy[i].z,xs,ys,zs);
				}
			}
		return;
		}

	if ( stage == 0 )
		{
		// 1面ボス
		// ジャンプ
		if ( enemy[i].yspeed == 0 && animecount == 0 )
			{
			enemy[i].yspeed = 20;
			}
		else
			{
			enemy[i].yspeed -= 2;
			if ( enemy[i].y <= 0x40 ) enemy[i].yspeed = 0;
			}
		}
	else if ( stage == 2 )
		{
		// ラスボス
		// ジャンプ
		if ( enemy[i].yspeed == 0 )
			{
			enemy[i].yspeed = random(30) + 10;
			}
		else
			{
			enemy[i].yspeed -= 4;
			if ( enemy[i].y <= 0x58 ) enemy[i].yspeed = 0;
			}
		}
	else
		{
		enemy[i].yspeed -= 2;
		if ( enemy[i].y <= 0x50 ) enemy[i].yspeed = 0;
		}

	if ( stage != 2 )
		{
		// ラスボス以外
		// 前に突っ込む
		if ( enemy[i].deg > 100 && enemy[i].deg < 120 )
			{
			enemy[i].zspeed = -0x12;
			}
		else if ( enemy[i].deg > 120 && enemy[i].deg < 140 )
			{
			enemy[i].zspeed = 0x12;
			}
		else
			{
			if ( random(5) == 0 ) enemymslinit(i);
			enemy[i].zspeed = 0;
			}
		}
	else
		{
		// ラスボス
		// 下がる
		if ( enemy[i].deg > 60 && enemy[i].deg < 80 )
			{
			enemy[i].zspeed = +0x1c;
			}
		else if ( enemy[i].deg > 80 && enemy[i].deg < 120 )
			{
			if ( random(3) < 2 ) enemyinit(0,E_MSL);
			}
		else if ( enemy[i].deg > 120 && enemy[i].deg < 140 )
			{
			enemy[i].zspeed = -0x1c;
			}
		else
			{
			if ( random(5) == 0 ) enemymslinit(i);
			enemy[i].zspeed = 0;
			}
		}
	if ( stage != 0 ) enemy[i].xspeed = dat[enemy[i].deg/20];

	enemy[i].x += enemy[i].xspeed;
	enemy[i].y += enemy[i].yspeed;
	enemy[i].z += enemy[i].zspeed;
	if ( enemy[i].x < -0x100 || enemy[i].x > FSX+0x100 ) enemy[i].flag = 0;
	if ( enemy[i].y < -0x500 || enemy[i].y > FSY+0x200 ) enemy[i].flag = 0;
	if ( enemy[i].z < -0x100 || enemy[i].z > FSZ+0x100 ) enemy[i].flag = 0;

	// 自弾との当たり判定
	for ( j = 0 ; j < MAXMSL ; j++ )
		{
		if ( msl[j].flag )
			{
			if ( mslhitcheck(i,j) )
				{
				enemy[i].hp--;
				if ( enemy[i].hp < 0 )
					{
					PcmPlay(1,ADP_ZBAKU);
					enemy[i].flag = 2;
					oe[i].geometryTop = model3;
					oe[i].geometryLength = sizeof(model3) / sizeof(int);
					oe[i].material = NULL;
					ship.score += enemy[i].score;
					}
				else
					{
					PcmPlay(1,ADP_DAMAGE);
					}
				msl[j].flag = 0;
				}
			}
		}
	}

